package com.csun.cmny.provider.controller.message;

import com.csun.cmny.base.dto.LoginAuthDto;
import com.csun.cmny.provider.dto.OrderQueryDto;
import com.csun.cmny.provider.vo.ExamineVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @Auther: chisj chisj@foxmal.com
 * @Date: 2019-10-11 19:52
 * @Description:
 */
@Component
public class CurTaskQueryHolder {

    private final Map<String, CurTaskQuery> curTaskQueryMap;

    @Autowired
    public CurTaskQueryHolder(Map<String, CurTaskQuery> curTaskQueryMap) {
        this.curTaskQueryMap = curTaskQueryMap;
    }

    public Object queryToDoList(LoginAuthDto loginAuthDto) {

        Map<String, Object> result = Maps.newHashMap();

        // 总条数
        int size = 0;
        List<ToDoVo> list = Lists.newArrayList();

        // 遍历所有的查询器
        for(Map.Entry<String, CurTaskQuery> entry : curTaskQueryMap.entrySet()) {

            Object obj = entry.getValue().queryToDoList(loginAuthDto);
            if (obj == null) {
                continue;
            }

            // ToDoVo toDoVo = (ToDoVo) entry.getValue().queryToDoList(loginAuthDto).clone();
            ToDoVo toDoVo = (ToDoVo) obj;

            if (toDoVo.getName() != null) {
                list.add(toDoVo);
                if(toDoVo.getData() != null){
                    size += toDoVo.getData().getSize();
                }
            }
        }

        result.put("size", size);
        result.put("list", list);

        return result;
    }


    public Object queryOrderList(OrderQueryDto orderQueryDto, LoginAuthDto loginAuthDto) {

        Map<String, Object> result = Maps.newHashMap();

        // 总条数
        int size = 0;
        List<ToDoVo> list = Lists.newArrayList();

        // 遍历所有的查询器
        for(Map.Entry<String, CurTaskQuery> entry : curTaskQueryMap.entrySet()) {

            Object obj = entry.getValue().queryOrderList(orderQueryDto, loginAuthDto);
            if (obj == null) {
                continue;
            }

            // ToDoVo toDoVo = (ToDoVo) entry.getValue().queryToDoList(loginAuthDto).clone();
            ToDoVo toDoVo = (ToDoVo) obj;



            if (toDoVo.getName() != null) {
                list.add(toDoVo);
                size += toDoVo.getData().getSize();
            }
        }

        result.put("size", size);
        result.put("list", list);

        return result;
    }
}
